package com.czjtxy.extraTerm.serverImpl;

import com.czjtxy.extraTerm.dao.TjobDao;
import com.czjtxy.extraTerm.daoImpl.TjobDaoImpl;
import com.czjtxy.extraTerm.entity.DO.Tjob;
import com.czjtxy.extraTerm.server.JobService;

import java.sql.SQLException;
import java.util.List;

/**
 * @program: staff-house
 * @author: MingYi
 * @create: 2021/07/01 16:05
 */
public class JobServiceImpl implements JobService {
    TjobDao tjobDao = new TjobDaoImpl();

    @Override
    public List<Tjob> getAll() throws SQLException {
        List<Tjob> tjobs = null;
        try {
            tjobs = tjobDao.getAll();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            tjobDao.closeResource();
        }
        return tjobs;
    }

    @Override
    public List<Tjob> getPart(String jobName) throws SQLException {
        List<Tjob> tjobs = null;
        try {
            tjobs = tjobDao.getPart(jobName);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            tjobDao.closeResource();
        }
        return tjobs;
    }

    @Override
    public Tjob getOne(int uid) throws SQLException {
        Tjob tjob = null;
        try {
            tjob = tjobDao.getOne(uid);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            tjobDao.closeResource();
        }
        return tjob;
    }

    @Override
    public void updateJob(Tjob tjob) throws SQLException {
        try {
            tjobDao.updateJob(tjob);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            tjobDao.closeResource();
        }
    }

    @Override
    public void deleteJob(String ids) throws SQLException {
        try {
            String[] idsArr = ids.split(",");
            for (String str : idsArr) {
                int id = Integer.parseInt(str);
                tjobDao.deleteJob(id);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            tjobDao.closeResource();
        }
    }

    @Override
    public void addJob(Tjob tjob) throws SQLException {
        try {
            tjobDao.addJob(tjob);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            tjobDao.closeResource();
        }
    }
}
